﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace week4
{
    public partial class Form1 : Form
    {
        Dictionary<string, string> path = new Dictionary<string, string>();
        public Form1()
        {
            InitializeComponent();
        }


        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                MyNode mn = (MyNode)e.Node;
                if (mn.isLoadFiles == false)
                {
                    DirectoryInfo di = new DirectoryInfo(mn.MyPath);
                    listView1.Items.Clear();
                    foreach (DirectoryInfo d in di.GetDirectories())//如果为文件夹
                    {
                        mn.Nodes.Add(new MyNode(d.FullName, false));
                        ListViewItem lvi = listView1.Items.Add(d.Name);
                        lvi.SubItems.Add("");
                        lvi.SubItems.Add("文件夹");
                        lvi.SubItems.Add(d.LastAccessTime.ToString());
                    }
                    foreach (FileInfo f in di.GetFiles())//如果为文件
                    {

                        ListViewItem lvi = listView1.Items.Add(f.Name, 0);
                        lvi.SubItems.Add(f.Length.ToString());
                        lvi.SubItems.Add("文件");
                        lvi.SubItems.Add(f.LastAccessTime.ToString());
                        path[f.Name] = mn.MyPath + "/" + f.Name;
                    }
                }
            }
            catch
            {
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            treeView1.Dock = System.Windows.Forms.DockStyle.Left;
            listView1.Dock = System.Windows.Forms.DockStyle.Fill;
            treeView1.TabIndex = 1;
            listView1.TabIndex = 2;
            MyNode mn = new MyNode(@"c:\", true);
            treeView1.Nodes.Add(mn);
            listView1.Columns.Add("名称", 150, HorizontalAlignment.Center);
            listView1.Columns.Add("大小", listView1.Width / 4, HorizontalAlignment.Center);
            listView1.Columns.Add("类型", listView1.Width / 4, HorizontalAlignment.Center);
            listView1.Columns.Add("修改时间",150, HorizontalAlignment.Center);
            listView1.View = View.Details;
            splitter1.Location = new System.Drawing.Point(120, 0);
            splitter1.Size = new System.Drawing.Size(3, 300);
            splitter1.TabIndex = 3;
            splitter1.TabStop = false;
        }

     

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (path.ContainsKey(listView1.SelectedItems[0].Text))
                System.Diagnostics.Process.Start(path[listView1.SelectedItems[0].Text]);
        }
    }

    
}
